|
1 | 1 | from datetime import datetime
|
| 2 | +import re |
2 | 3 | from playwright_tests.core.basepage import BasePage
|
3 | 4 | from playwright_tests.core.utilities import Utilities
|
4 | 5 |
|
@@ -56,24 +57,38 @@ def __init__(self, page):
|
56 | 57 | self.post_content = lambda post_id: page.locator(
|
57 | 58 | f"//li[@id='post-{post_id}']//div[@class='content']/p")
|
58 | 59 | self.thread_post = lambda post_id: page.locator(f"li#post-{post_id}")
|
| 60 | + self.thread_post_by_content = lambda post_content: page.locator( |
| 61 | + f"//div[@class='content']/p[normalize-space(text())='{post_content}']") |
| 62 | + self.modified_by = lambda post_id: page.locator(f"li#post-{post_id} p.text-body-sm") |
| 63 | + self.quoted_thread_post_mention = lambda post_id: page.locator( |
| 64 | + f"li#post-{post_id} div.content em") |
| 65 | + self.quoted_thread_post_mention_link = lambda post_id: page.locator( |
| 66 | + f"li#post-{post_id} div.content em a") |
| 67 | + self.quoted_thread_post_quote = lambda post_id: page.locator( |
| 68 | + f"li#post-{post_id} div.content blockquote") |
59 | 69 |
|
60 | 70 | # Thread post more options locators
|
61 | 71 | self.post_3_dotted_menu = lambda post_id: page.locator(f"li#post-{post_id}").get_by_role(
|
62 | 72 | "button", name="more options")
|
| 73 | + self.post_3_dotted_menu_expanded = lambda post_id: page.locator( |
| 74 | + f"//li[@id='post-{post_id}']//ul[contains(@id,'expand-datahasdropdown')]") |
| 75 | + self.private_message = lambda post_id: page.locator( |
| 76 | + f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role( |
| 77 | + "link", name="Private message") |
63 | 78 | self.post_edit_this_post = lambda post_id: page.locator(
|
64 |
| - f"li#post-{post_id} ul#expand-expand-datahasdropdown-0 li").get_by_role( |
| 79 | + f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role( |
65 | 80 | "link", name="Edit this post")
|
66 | 81 | self.delete_this_post = lambda post_id: page.locator(
|
67 |
| - f"li#post-{post_id} ul#expand-expand-datahasdropdown-0 li").get_by_role( |
| 82 | + f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role( |
68 | 83 | "link", name="Delete this post")
|
69 | 84 | self.quote_this_post = lambda post_id: page.locator(
|
70 |
| - f"li#post-{post_id} ul#expand-expand-datahasdropdown-0 li").get_by_role( |
| 85 | + f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role( |
71 | 86 | "link", name="Quote")
|
72 | 87 | self.report_this_post = lambda post_id: page.locator(
|
73 |
| - f"li#post-{post_id} ul#expand-expand-datahasdropdown-0 li").get_by_role( |
| 88 | + f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role( |
74 | 89 | "link", name="Report Abuse")
|
75 | 90 | self.link_this_post = lambda post_id: page.locator(
|
76 |
| - f"li#post-{post_id} ul#expand-expand-datahasdropdown-0 li").get_by_role( |
| 91 | + f"li#post-{post_id} li.mzp-c-menu-list-item").get_by_role( |
77 | 92 | "link", name="Link to this post")
|
78 | 93 |
|
79 | 94 | # Post a reply locators
|
@@ -118,6 +133,26 @@ def is_thread_post_visible(self, post_id: str) -> bool:
|
118 | 133 | """
|
119 | 134 | return self._is_element_visible(self.thread_post(post_id))
|
120 | 135 |
|
| 136 | + def is_thread_post_by_name_visible(self, post_name: str) -> bool: |
| 137 | + """ |
| 138 | + Check if a specific thread post by name is visible. |
| 139 | + Args: |
| 140 | + post_name (str): The name of the post. |
| 141 | + Returns: |
| 142 | + bool: True if the post is visible, False otherwise. |
| 143 | + """ |
| 144 | + return self._is_element_visible(self.thread_post_by_content(post_name)) |
| 145 | + |
| 146 | + def get_modified_by_text(self, post_id: str) -> str: |
| 147 | + """ |
| 148 | + Get the modified by text for a specific post. |
| 149 | + Args: |
| 150 | + post_id (str): The ID of the post. |
| 151 | + Returns: |
| 152 | + str: The modified by text. |
| 153 | + """ |
| 154 | + return self._get_text_of_element(self.modified_by(post_id)) |
| 155 | + |
121 | 156 | def is_edit_thread_title_option_visible(self) -> bool:
|
122 | 157 | """
|
123 | 158 | Check if the edit thread title option is visible.
|
@@ -299,3 +334,140 @@ def click_on_contributor_discussions_side_navbar_item(self, item_name: str):
|
299 | 334 | item_name (str): The name of the item to click on.
|
300 | 335 | """
|
301 | 336 | self._click(self.contributor_discussions_side_navbar_item(item_name))
|
| 337 | + |
| 338 | + def click_on_3_dotted_menu(self, post_id: str): |
| 339 | + """ |
| 340 | + Click on the 3-dotted menu for a specific post. |
| 341 | + Args: |
| 342 | + post_id (str): The ID of the post. |
| 343 | + """ |
| 344 | + self._click(self.post_3_dotted_menu(post_id), |
| 345 | + expected_locator=self.post_3_dotted_menu_expanded(post_id)) |
| 346 | + |
| 347 | + def click_on_edit_this_post_option(self, post_id: str): |
| 348 | + """ |
| 349 | + 1. Click on the "Edit this post" option for a specific post. |
| 350 | + 2. Click on the "Edit this post" option in the 3-dotted menu of the post. |
| 351 | + Args: |
| 352 | + post_id (str): The ID of the post. |
| 353 | + """ |
| 354 | + self.click_on_3_dotted_menu(post_id) |
| 355 | + self._click(self.post_edit_this_post(post_id)) |
| 356 | + |
| 357 | + def is_edit_this_post_option_displayed(self, post_id: str): |
| 358 | + """ |
| 359 | + Check if the "Edit this post" option is displayed in the 3-dotted menu of a specific post. |
| 360 | + Args: |
| 361 | + post_id (str): The ID of the post. |
| 362 | + Returns: |
| 363 | + bool: True if the option is displayed, False otherwise. |
| 364 | + """ |
| 365 | + self.click_on_3_dotted_menu(post_id) |
| 366 | + return self._is_element_visible(self.post_edit_this_post(post_id)) |
| 367 | + |
| 368 | + def is_delete_this_post_option_displayed(self, post_id: str): |
| 369 | + """ |
| 370 | + Check if the "Delete this post" option is displayed in the 3-dotted menu of a specific |
| 371 | + post. |
| 372 | + Args: |
| 373 | + post_id (str): The ID of the post. |
| 374 | + Returns: |
| 375 | + bool: True if the option is displayed, False otherwise. |
| 376 | + """ |
| 377 | + self.click_on_3_dotted_menu(post_id) |
| 378 | + return self._is_element_visible(self.delete_this_post(post_id)) |
| 379 | + |
| 380 | + def click_on_quote_option(self, post_id: str): |
| 381 | + """ |
| 382 | + Click on the "Quote" option for a specific post. |
| 383 | + Args: |
| 384 | + post_id (str): The ID of the post. |
| 385 | + """ |
| 386 | + self.click_on_3_dotted_menu(post_id) |
| 387 | + self._click(self.quote_this_post(post_id)) |
| 388 | + |
| 389 | + def click_on_delete_this_post_option(self, post_id: str): |
| 390 | + """ |
| 391 | + Click on the "Delete this post" option for a specific post. |
| 392 | + Args: |
| 393 | + post_id (str): The ID of the post. |
| 394 | + """ |
| 395 | + self.click_on_3_dotted_menu(post_id) |
| 396 | + self._click(self.delete_this_post(post_id)) |
| 397 | + |
| 398 | + def click_on_private_message_option(self, post_id: str): |
| 399 | + """ |
| 400 | + Click on the "Private message" option for a specific post. |
| 401 | + Args: |
| 402 | + post_id (str): The ID of the post. |
| 403 | + """ |
| 404 | + self.click_on_3_dotted_menu(post_id) |
| 405 | + self._click(self.private_message(post_id)) |
| 406 | + |
| 407 | + def is_quote_option_displayed(self, post_id: str) -> bool: |
| 408 | + """ |
| 409 | + Check if the "Quote" option is displayed in the 3-dotted menu of a specific post. |
| 410 | + Returns: |
| 411 | + bool: True if the option is displayed, False otherwise. |
| 412 | + """ |
| 413 | + self.click_on_3_dotted_menu(post_id) |
| 414 | + return self._is_element_visible(self.quote_this_post(post_id)) |
| 415 | + |
| 416 | + def click_on_report_abuse_option(self, post_id: str): |
| 417 | + """ |
| 418 | + Click on the "Report Abuse" option for a specific post. |
| 419 | + Args: |
| 420 | + post_id (str): The ID of the post. |
| 421 | + """ |
| 422 | + self.click_on_3_dotted_menu(post_id) |
| 423 | + self._click(self.report_this_post(post_id)) |
| 424 | + |
| 425 | + def click_on_link_to_this_post_option(self, post_id: str) -> str: |
| 426 | + """ |
| 427 | + Click on the "Link to this post" option for a specific post. |
| 428 | + Args: |
| 429 | + post_id (str): The ID of the post. |
| 430 | + Returns: |
| 431 | + str: The ID of the post. |
| 432 | + """ |
| 433 | + self.click_on_3_dotted_menu(post_id) |
| 434 | + self._click(self.link_this_post(post_id)) |
| 435 | + |
| 436 | + return re.search(r'post-(\d+)', self.utilities.get_page_url()).group(1) |
| 437 | + |
| 438 | + def is_report_abuse_option_displayed(self, post_id: str) -> bool: |
| 439 | + """ |
| 440 | + Check if the "Report Abuse" option is displayed in the 3-dotted menu of a specific post. |
| 441 | + Args: |
| 442 | + post_id (str): The ID of the post. |
| 443 | + Returns: |
| 444 | + bool: True if the option is displayed, False otherwise. |
| 445 | + """ |
| 446 | + self.click_on_3_dotted_menu(post_id) |
| 447 | + return self._is_element_visible(self.report_this_post(post_id)) |
| 448 | + |
| 449 | + def get_thread_post_mention_text(self, post_id: str) -> str: |
| 450 | + """ |
| 451 | + Get the thread post mention text for a specific post. |
| 452 | + Args: |
| 453 | + post_id (str): The ID of the post. |
| 454 | + Returns: |
| 455 | + str: The thread post mention text. |
| 456 | + """ |
| 457 | + return self._get_text_of_element(self.quoted_thread_post_mention(post_id)) |
| 458 | + |
| 459 | + def click_on_post_mention_link(self, post_id: str): |
| 460 | + """ |
| 461 | + Click on the post mention link. |
| 462 | + """ |
| 463 | + self._click(self.quoted_thread_post_mention_link(post_id)) |
| 464 | + |
| 465 | + def get_thread_post_quote_text(self, post_id: str) -> str: |
| 466 | + """ |
| 467 | + Get the thread post quote text for a specific post. |
| 468 | + Args: |
| 469 | + post_id (str): The ID of the post. |
| 470 | + Returns: |
| 471 | + str: The thread post quote text. |
| 472 | + """ |
| 473 | + return self._get_text_of_element(self.quoted_thread_post_quote(post_id)) |
0 commit comments